<script setup>
import { Search, ArrowDown } from '@element-plus/icons-vue'
import { ref, onMounted } from 'vue'
import { getFriendListApi } from '@/api/friend'
import { useUserStore } from '@/stores'

//用户个人信息
const userInfo = useUserStore().getUser()

//搜索内容
const text = ref('')

//导航栏
const navList = ref(['最近聊天', '我的好友'])
//点击搜索按钮

//
const flag = ref(false)
const Index = ref(0)

//好友列表
const friendList = ref([])

//被选中的联系人数
const num = ref(0)

//获取好友列表
const getFriendList = async () => {
  const res = await getFriendListApi(userInfo.userId)
  friendList.value = res.data.data
  console.log('好友列表：', res)
}

//渲染好友列表
onMounted(() => {
  getFriendList()
})
</script>

<template>
  <div class="create-group">
    <el-container>
      <el-aside width="250px">
        <div class="search-input">
          <el-input v-model="text" :prefix-icon="Search" placeholder="搜索"></el-input>
        </div>
        <div class="tip">选择好友创建</div>
        <div class="nav-list">
          <div v-for="(item, index) in navList" :key="index" class="item">
            <div @click="((Index = index), (flag = !flag))" class="item-content">
              <div class="icon">
                <el-icon><ArrowDown /></el-icon>
              </div>
              <div class="text">{{ item }}</div>
            </div>
            <div v-if="Index === index && flag && item === '最近聊天'">
              <list-index></list-index>
            </div>
            <div
              v-for="(item, index) in friendList"
              :key="index"
              v-else-if="Index == index && flag && item == '我的好友'"
              class="friend"
            >
              <div>
                <el-checkbox :value="item.id" />
              </div>
              <list-index class="friend-item" :item="item"></list-index>
            </div>
          </div>
        </div>
      </el-aside>

      <el-main>
        <div class="group-info">
          <div class="group-name">
            <div class="title">创建群聊</div>
            <div class="num">已选择{{ num }}个联系人</div>
          </div>
          <div class="selected-friend-list">
            <div class="item">1</div>
          </div>
        </div>
        <div class="opt-button">
          <el-button type="primary">确定</el-button>
          <el-button>取消</el-button>
        </div>
      </el-main>
    </el-container>
  </div>
</template>

<style lang="scss" scoped>
.friend {
  height: 40px;
  display: flex;
  align-items: center;
  margin-top: 5px;
}
.friend:hover {
  background-color: #f2f2f2;
}

.create-group {
  z-index: 999;
  width: 500px;
  height: 500px;
  position: absolute;
  background-color: white;
  border: 1px solid #ccc;
  top: 15%;
  left: 35%;
  position: absolute;
  border-radius: 10px;
  .el-main {
    display: flex;
    flex-direction: column;
    padding: 5px;
    font-size: 14px;
    justify-content: space-between;
    .group-info {
      .group-name {
        display: flex;
        justify-content: space-between;
        .num {
          font-size: 12px;
          color: #999;
        }
      }
    }
    .opt-button {
      margin-left: 80px;
      button {
        width: 70px;
      }
    }
  }
  .el-aside {
    border-right: 1px dashed #ccc;
    height: 500px;
    justify-content: space-between;

    .search-input {
      border-bottom: 1px dashed #ccc;
      padding: 20px;
    }
    .tip {
      padding-bottom: 5px;
      margin: 10px;
      font-size: 14px;
      border-bottom: 1px solid #ccc;
    }
    .nav-list {
      margin: 10px;
      .item {
        font-size: 14px;
        .item-content {
          display: flex;
          align-items: center;
        }
      }
    }
  }
}
</style>
